<template>
  <div>
    <div>
      客诉管理
    </div>
    <div class="search-box">
      <el-form ref="filter" label-width="70px" label-position="left" :model="filter" style="display: flex">
        <el-form-item label="标题">
          <el-input v-model="filter.title" size="small" style="width:200px;margin-right:20px;"></el-input>
        </el-form-item>
        <el-form-item label="类型">
          <el-select v-model="filter.type" size="small" placeholder="请选择类型" style="width:200px;margin-right:20px;">
            <el-option label="1" value="1"></el-option>
            <el-option label="2" value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="作者">
          <el-input v-model="filter.author" size="small" style="width:200px;margin-right:20px;"></el-input>
        </el-form-item>
        <el-form-item label="详情">
          <el-input v-model="filter.remark1" size="small" style="width:200px;margin-right:20px;"></el-input>
        </el-form-item>
        <el-form-item label="顺序">
          <el-input v-model="filter.order" size="small" style="width:200px;margin-right:20px;"></el-input>
        </el-form-item>
      </el-form>
      <el-button size="small" type="warning" @click="search">查询</el-button>
      <el-button size="small" type="" @click="reset">重置</el-button>
    </div>
    <!--参数列表-->
    <div style="overflow:hidden;border-top:1px solid #ccc">
      <el-table :data="customerList" stripe style="width:100%" v-loading="loading">
        <el-table-column prop="type" label="类型" min-width="80"></el-table-column>
        <el-table-column prop="title" label="标题" min-width="80"></el-table-column>
        <el-table-column prop="author" label="作者" min-width="80"></el-table-column>
        <el-table-column prop="remark1" label="详细原因" min-width="200"></el-table-column>
        <el-table-column prop="order" label="顺序" min-width="80"></el-table-column>
        <el-table-column prop="file" label="附件" min-width="80"></el-table-column>
        <el-table-column prop="createTime" label="创建时间" min-width="80"></el-table-column>
      </el-table>
      <!--分页功能-->
      <el-pagination
        style="margin-top:20px;justify-content:flex-end;display:flex;"
        @size-change="sizeChange"
        @current-change="currentChange"
        :current-page.sync="currentPage"
        :page-size="10"
        layout="prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
  import server from '../../services/index'
  export default {
    components: {},
    data () {
      return {
        filter:{
          title:"",
          type:"",
          author:"",
          remark1:"",
          order:"",
        },
        customerList: [],
        loading: false,
        total: 0,
        currentPage: 1,
        pageSize: 10,
      }
    },
    methods:{
      getListData(){
        this.loading = true;
        let params = {
          pageSize: this.pageSize,
          pageNum: this.currentPage,
        }
        $.ajax({
          url:server.customerList.url,
          type:'get',
          data:params,
          dataType:'json',
          success:res => {
            if(res.code == 1){
              this.loading = false;
              this.customerList = res.result.questionsList;
              this.total = res.result.total;
            }
          },
          error:err =>{
            this.$message({
              message: err.responseJSON.error,
              type: 'error'
            });
          }
        });
      },
      sizeChange(val){
        this.pageSize = val;
        this.getListData();
      },
      currentChange(val){
        this.currentPage = val;
        this.getListData();
      },
      search(){
        this.loading = true;
        let params = {
          pageSize: this.pageSize,
          pageNum: this.currentPage,
        }
        /*title:"",
          type:"",
          author:"",
          remark1:"",
          order:"",*/
        if(this.filter.title) params.title = this.filter.title;
        if(this.filter.type) params.type = this.filter.type;
        if(this.filter.author) params.author = this.filter.author;
        if(this.filter.remark1) params.remark1 = this.filter.remark1;
        if(this.filter.order) params.order = this.filter.order;
        $.ajax({
          url:server.searchCustomerList.url,
          type:'get',
          data:params,
          dataType:'json',
          success:res => {
            if(res.code == 1){
              this.loading = false;
              if(res.msg=='未找到相关订单'){
                this.customerList = [];
              }else{
                this.customerList = res.result.questionList;
                this.total = res.result.total;
              }
            }
          },
          error:err =>{
            this.$message({
              message: err.responseJSON.error,
              type: 'error'
            });
          }
        });
      },
      reset(){
        this.filter.markId = "";
        this.filter.type = "";
        this.filter.price = "";
        this.filter.count = "";
        this.filter.time = "";
        this.getListData();
      },
      getNowFormatDate(time) {
        var date = time;
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        if (month >= 1 && month <= 9) {
          month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
          strDate = "0" + strDate;
        }
        var currentdate = year + "-" + month + "-" + strDate;
        return currentdate;
      },
    },
    mounted(){
      if(!window.sessionStorage.getItem("token"))this.$router.push({path: '/'});
      this.getListData()
    }
  }
</script>

<style scoped>
  .search-box{
    margin: 20px 0;
  }
</style>
